<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>对除法结果取整</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.intdiv" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">intdiv</h1>
  <p class="verinfo">(PHP 7)</p><p class="refpurpose"><span class="refname">intdiv</span> &mdash; <span class="dc-title">对除法结果取整</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.intdiv-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
    <span class="methodname"><strong>intdiv</strong></span>
     ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$dividend</code></span>
    , <span class="methodparam"><span class="type">int</span> <code class="parameter">$divisor</code></span>
    ) : <span class="type">int</span></div>

  <p class="para rdfs-comment">
   返回 <code class="parameter">dividend</code> 除以 <code class="parameter">divisor</code> 商数的整数部分。
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.intdiv-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<code class="parameter">dividend</code></dt>

    <dd>

     <p class="para">
      被除数。
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">divisor</code></dt>

    <dd>

     <p class="para">
      除数。
     </p>
    </dd>

   
  </dl>

 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.intdiv-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <code class="parameter">dividend</code> 除以 <code class="parameter">divisor</code> 的商，对该商取整。
  </p>
 </div>

 <div class="refsect1 errors" id="refsect1-function.intdiv-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
    如果 <code class="parameter">divisor</code> 是 <em>0</em>，将抛出 <strong class="classname">DivisionByZeroError</strong> 异常。
    如果 <code class="parameter">dividend</code> 是 <strong><code>PHP_INT_MIN</code></strong>
    并且 <code class="parameter">divisor</code> 是 <em>-1</em>，将抛出 <strong class="classname">ArithmeticError</strong> 异常.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.intdiv-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4130">
    <p><strong>Example #1 <span class="function"><strong>intdiv()</strong></span> 的一些例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">intdiv</span><span style="color: #007700">(</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">intdiv</span><span style="color: #007700">(-</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">intdiv</span><span style="color: #007700">(</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">2</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">intdiv</span><span style="color: #007700">(-</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">2</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">intdiv</span><span style="color: #007700">(</span><span style="color: #0000BB">PHP_INT_MAX</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_INT_MAX</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">intdiv</span><span style="color: #007700">(</span><span style="color: #0000BB">PHP_INT_MIN</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_INT_MIN</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">intdiv</span><span style="color: #007700">(</span><span style="color: #0000BB">PHP_INT_MIN</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">1</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">intdiv</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents screen">
<div class="cdata"><pre>
int(1)
int(-1)
int(-1)
int(1)
int(1)
int(1)

Fatal error: Uncaught ArithmeticError: Division of PHP_INT_MIN by -1 is not an integer in %s on line 8
Fatal error: Uncaught DivisionByZeroError: Division by zero in %s on line 9
</pre></div>
    </div>
   </div>
  </p>
 </div>
 
</div></div></div></body></html>